package com.jenkins.test.security;

import org.springframework.stereotype.Component;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @version V1.0.0
 * @ClassName: {@link LoginUserStorage}
 * @Description: LoginUserStorage
 * @author: Lanzhou
 * @date: 2021/6/25 12:33
 * @Copyright:2020 All rights reserved.
 */
@Component
public class LoginUserStorage {

    private ConcurrentHashMap<String, LoginUser> loginCache = new ConcurrentHashMap<>();

    /**
     * 缓存用户
     *
     * @param key
     * @param loginUser
     */
    public void cacheLoginUser(String key, LoginUser loginUser) {
        this.loginCache.put(key, loginUser);
    }


    /**
     * 删除用户
     *
     * @param key
     */
    public void deleteLoginUser(String key) {
        this.loginCache.remove(key);
    }

    /**
     * 获取用户
     *
     * @param key
     */
    public LoginUser getLoginUser(String key) {
        return this.loginCache.get(key);
    }

    public void setLoginCache(ConcurrentHashMap<String, LoginUser> loginCache) {
        this.loginCache = loginCache;
    }
}
